'use strict';
const fs = require('fs');
module.exports = async function (ctx, options) {
        let param = ctx.method === 'GET' ? ctx.query : ctx.request.fields;
        // let action_type = param.action_type;
        try {
            ctx.set('Content-type', 'application/xlsx');
            ctx.attachment(param.fileName);
            ctx.body = fs.createReadStream('export/' + param.fileName);
            let deleteTimeout =setTimeout(function () {
                fs.unlink('export/' + param.fileName,function(error){
                    if(error){
                        console.log(error);
                        return false;
                    }
                });
                clearTimeout(deleteTimeout)
            },60000)

        }catch (e) {
            ctx.body = {success: false, message: e.message};
        }

};